package com.wenhai.spring.dependency.source;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;
import org.springframework.core.io.Resource;

/**
 * @Author:wenhai
 * @Description: 外部化配置
 * @Date:2020/3/15
 */
@PropertySource(value = "classpath:/META-INF/default.properties",encoding = "UTF-8")
@Configuration
public class ExternalConfigurationDependencySourceDemo {
    @Value("${user.id:-1}")
    private Long id;

    @Value("${user.resource:classpath:/default.properties}")
    private Resource resource;
    public static void main(String[] args) {
        AnnotationConfigApplicationContext annotationConfigApplicationContext = new AnnotationConfigApplicationContext();
        annotationConfigApplicationContext.register(ExternalConfigurationDependencySourceDemo.class);
        annotationConfigApplicationContext.refresh();

        ExternalConfigurationDependencySourceDemo bean = annotationConfigApplicationContext.getBean(ExternalConfigurationDependencySourceDemo.class);
        System.out.println(bean.id);
        System.out.println(bean.resource);
        annotationConfigApplicationContext.close();
    }
}
